1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gtk.MenuButton;
26 
27 private import gio.MenuModel;
28 private import glib.ConstructionException;
29 private import glib.Str;
30 private import glib.c.functions;
31 private import gobject.ObjectG;
32 private import gobject.Signals;
33 private import gtk.Popover;
34 private import gtk.Widget;
35 private import gtk.c.functions;
36 public  import gtk.c.types;
37 private import std.algorithm;
38 
39 
40 /**
41  * The `GtkMenuButton` widget is used to display a popup when clicked.
42  * 
43  * ![An example GtkMenuButton](menu-button.png)
44  * 
45  * This popup can be provided either as a `GtkPopover` or as an abstract
46  * `GMenuModel`.
47  * 
48  * The `GtkMenuButton` widget can show either an icon (set with the
49  * [property@Gtk.MenuButton:icon-name] property) or a label (set with the
50  * [property@Gtk.MenuButton:label] property). If neither is explicitly set,
51  * a [class@Gtk.Image] is automatically created, using an arrow image oriented
52  * according to [property@Gtk.MenuButton:direction] or the generic
53  * “open-menu-symbolic” icon if the direction is not set.
54  * 
55  * The positioning of the popup is determined by the
56  * [property@Gtk.MenuButton:direction] property of the menu button.
57  * 
58  * For menus, the [property@Gtk.Widget:halign] and [property@Gtk.Widget:valign]
59  * properties of the menu are also taken into account. For example, when the
60  * direction is %GTK_ARROW_DOWN and the horizontal alignment is %GTK_ALIGN_START,
61  * the menu will be positioned below the button, with the starting edge
62  * (depending on the text direction) of the menu aligned with the starting
63  * edge of the button. If there is not enough space below the button, the
64  * menu is popped up above the button instead. If the alignment would move
65  * part of the menu offscreen, it is “pushed in”.
66  * 
67  * |           | start                | center                | end                |
68  * | -         | ---                  | ---                   | ---                |
69  * | **down**  | ![](down-start.png)  | ![](down-center.png)  | ![](down-end.png)  |
70  * | **up**    | ![](up-start.png)    | ![](up-center.png)    | ![](up-end.png)    |
71  * | **left**  | ![](left-start.png)  | ![](left-center.png)  | ![](left-end.png)  |
72  * | **right** | ![](right-start.png) | ![](right-center.png) | ![](right-end.png) |
73  * 
74  * # CSS nodes
75  * 
76  * ```
77  * menubutton
78  * ╰── button.toggle
79  * ╰── <content>
80  * ╰── [arrow]
81  * ```
82  * 
83  * `GtkMenuButton` has a single CSS node with name `menubutton`
84  * which contains a `button` node with a `.toggle` style class.
85  * 
86  * If the button contains an icon, it will have the `.image-button` style class,
87  * if it contains text, it will have `.text-button` style class. If an arrow is
88  * visible in addition to an icon, text or a custom child, it will also have
89  * `.arrow-button` style class.
90  * 
91  * Inside the toggle button content, there is an `arrow` node for
92  * the indicator, which will carry one of the `.none`, `.up`, `.down`,
93  * `.left` or `.right` style classes to indicate the direction that
94  * the menu will appear in. The CSS is expected to provide a suitable
95  * image for each of these cases using the `-gtk-icon-source` property.
96  * 
97  * Optionally, the `menubutton` node can carry the `.circular` style class
98  * to request a round appearance.
99  * 
100  * # Accessibility
101  * 
102  * `GtkMenuButton` uses the %GTK_ACCESSIBLE_ROLE_BUTTON role.
103  */
104 public class MenuButton : Widget
105 {
106 	/** the main Gtk struct */
107 	protected GtkMenuButton* gtkMenuButton;
108 
109 	/** Get the main Gtk struct */
110 	public GtkMenuButton* getMenuButtonStruct(bool transferOwnership = false)
111 	{
112 		if (transferOwnership)
113 			ownedRef = false;
114 		return gtkMenuButton;
115 	}
116 
117 	/** the main Gtk struct as a void* */
118 	protected override void* getStruct()
119 	{
120 		return cast(void*)gtkMenuButton;
121 	}
122 
123 	/**
124 	 * Sets our main struct and passes it to the parent class.
125 	 */
126 	public this (GtkMenuButton* gtkMenuButton, bool ownedRef = false)
127 	{
128 		this.gtkMenuButton = gtkMenuButton;
129 		super(cast(GtkWidget*)gtkMenuButton, ownedRef);
130 	}
131 
132 
133 	/** */
134 	public static GType getType()
135 	{
136 		return gtk_menu_button_get_type();
137 	}
138 
139 	/**
140 	 * Creates a new `GtkMenuButton` widget with downwards-pointing
141 	 * arrow as the only child.
142 	 *
143 	 * You can replace the child widget with another `GtkWidget`
144 	 * should you wish to.
145 	 *
146 	 * Returns: The newly created `GtkMenuButton`
147 	 *
148 	 * Throws: ConstructionException GTK+ fails to create the object.
149 	 */
150 	public this()
151 	{
152 		auto __p = gtk_menu_button_new();
153 
154 		if(__p is null)
155 		{
156 			throw new ConstructionException("null returned by new");
157 		}
158 
159 		this(cast(GtkMenuButton*) __p);
160 	}
161 
162 	/**
163 	 * Gets whether to show a dropdown arrow even when using an icon.
164 	 *
165 	 * Returns: whether to show a dropdown arrow even when using an icon
166 	 *
167 	 * Since: 4.4
168 	 */
169 	public bool getAlwaysShowArrow()
170 	{
171 		return gtk_menu_button_get_always_show_arrow(gtkMenuButton) != 0;
172 	}
173 
174 	/**
175 	 * Gets the child widget of @menu_button.
176 	 *
177 	 * Returns: the child widget of @menu_button
178 	 *
179 	 * Since: 4.6
180 	 */
181 	public Widget getChild()
182 	{
183 		auto __p = gtk_menu_button_get_child(gtkMenuButton);
184 
185 		if(__p is null)
186 		{
187 			return null;
188 		}
189 
190 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) __p);
191 	}
192 
193 	/**
194 	 * Returns the direction the popup will be pointing at when popped up.
195 	 *
196 	 * Returns: a `GtkArrowType` value
197 	 */
198 	public GtkArrowType getMenuDirection()
199 	{
200 		return gtk_menu_button_get_direction(gtkMenuButton);
201 	}
202 
203 	/**
204 	 * Returns whether the button has a frame.
205 	 *
206 	 * Returns: %TRUE if the button has a frame
207 	 */
208 	public bool getHasFrame()
209 	{
210 		return gtk_menu_button_get_has_frame(gtkMenuButton) != 0;
211 	}
212 
213 	/**
214 	 * Gets the name of the icon shown in the button.
215 	 *
216 	 * Returns: the name of the icon shown in the button
217 	 */
218 	public string getIconName()
219 	{
220 		return Str.toString(gtk_menu_button_get_icon_name(gtkMenuButton));
221 	}
222 
223 	/**
224 	 * Gets the label shown in the button
225 	 *
226 	 * Returns: the label shown in the button
227 	 */
228 	public string getLabel()
229 	{
230 		return Str.toString(gtk_menu_button_get_label(gtkMenuButton));
231 	}
232 
233 	/**
234 	 * Returns the `GMenuModel` used to generate the popup.
235 	 *
236 	 * Returns: a `GMenuModel`
237 	 */
238 	public MenuModel getMenuModel()
239 	{
240 		auto __p = gtk_menu_button_get_menu_model(gtkMenuButton);
241 
242 		if(__p is null)
243 		{
244 			return null;
245 		}
246 
247 		return ObjectG.getDObject!(MenuModel)(cast(GMenuModel*) __p);
248 	}
249 
250 	/**
251 	 * Returns the `GtkPopover` that pops out of the button.
252 	 *
253 	 * If the button is not using a `GtkPopover`, this function
254 	 * returns %NULL.
255 	 *
256 	 * Returns: a `GtkPopover` or %NULL
257 	 */
258 	public Popover getPopover()
259 	{
260 		auto __p = gtk_menu_button_get_popover(gtkMenuButton);
261 
262 		if(__p is null)
263 		{
264 			return null;
265 		}
266 
267 		return ObjectG.getDObject!(Popover)(cast(GtkPopover*) __p);
268 	}
269 
270 	/**
271 	 * Returns whether the menu button acts as a primary menu.
272 	 *
273 	 * Returns: %TRUE if the button is a primary menu
274 	 *
275 	 * Since: 4.4
276 	 */
277 	public bool getPrimary()
278 	{
279 		return gtk_menu_button_get_primary(gtkMenuButton) != 0;
280 	}
281 
282 	/**
283 	 * Returns whether an embedded underline in the text indicates a
284 	 * mnemonic.
285 	 *
286 	 * Returns: %TRUE whether an embedded underline in the text indicates
287 	 *     the mnemonic accelerator keys.
288 	 */
289 	public bool getUseUnderline()
290 	{
291 		return gtk_menu_button_get_use_underline(gtkMenuButton) != 0;
292 	}
293 
294 	/**
295 	 * Dismiss the menu.
296 	 */
297 	public void popdown()
298 	{
299 		gtk_menu_button_popdown(gtkMenuButton);
300 	}
301 
302 	/**
303 	 * Pop up the menu.
304 	 */
305 	public void popup()
306 	{
307 		gtk_menu_button_popup(gtkMenuButton);
308 	}
309 
310 	/**
311 	 * Sets whether to show a dropdown arrow even when using an icon or a custom
312 	 * child.
313 	 *
314 	 * Params:
315 	 *     alwaysShowArrow = hether to show a dropdown arrow even when using an icon
316 	 *
317 	 * Since: 4.4
318 	 */
319 	public void setAlwaysShowArrow(bool alwaysShowArrow)
320 	{
321 		gtk_menu_button_set_always_show_arrow(gtkMenuButton, alwaysShowArrow);
322 	}
323 
324 	/**
325 	 * Sets the child widget of @menu_button.
326 	 *
327 	 * Setting a child resets [property@Gtk.MenuButton:label] and
328 	 * [property@Gtk.MenuButton:icon-name].
329 	 *
330 	 * If [property@Gtk.MenuButton:always-show-arrow] is set to `TRUE` and
331 	 * [property@Gtk.MenuButton:direction] is not `GTK_ARROW_NONE`, a dropdown arrow
332 	 * will be shown next to the child.
333 	 *
334 	 * Params:
335 	 *     child = the child widget
336 	 *
337 	 * Since: 4.6
338 	 */
339 	public void setChild(Widget child)
340 	{
341 		gtk_menu_button_set_child(gtkMenuButton, (child is null) ? null : child.getWidgetStruct());
342 	}
343 
344 	/**
345 	 * Sets @func to be called when a popup is about to be shown.
346 	 *
347 	 * @func should use one of
348 	 *
349 	 * - [method@Gtk.MenuButton.set_popover]
350 	 * - [method@Gtk.MenuButton.set_menu_model]
351 	 *
352 	 * to set a popup for @menu_button.
353 	 * If @func is non-%NULL, @menu_button will always be sensitive.
354 	 *
355 	 * Using this function will not reset the menu widget attached to
356 	 * @menu_button. Instead, this can be done manually in @func.
357 	 *
358 	 * Params:
359 	 *     func = function to call when a popup is about to
360 	 *         be shown, but none has been provided via other means, or %NULL
361 	 *         to reset to default behavior.
362 	 *     userData = user data to pass to @func.
363 	 *     destroyNotify = destroy notify for @user_data
364 	 */
365 	public void setCreatePopupFunc(GtkMenuButtonCreatePopupFunc func, void* userData, GDestroyNotify destroyNotify)
366 	{
367 		gtk_menu_button_set_create_popup_func(gtkMenuButton, func, userData, destroyNotify);
368 	}
369 
370 	/**
371 	 * Sets the direction in which the popup will be popped up.
372 	 *
373 	 * If the button is automatically populated with an arrow icon,
374 	 * its direction will be changed to match.
375 	 *
376 	 * If the does not fit in the available space in the given direction,
377 	 * GTK will its best to keep it inside the screen and fully visible.
378 	 *
379 	 * If you pass %GTK_ARROW_NONE for a @direction, the popup will behave
380 	 * as if you passed %GTK_ARROW_DOWN (although you won’t see any arrows).
381 	 *
382 	 * Params:
383 	 *     direction = a `GtkArrowType`
384 	 */
385 	public void setMenuDirection(GtkArrowType direction)
386 	{
387 		gtk_menu_button_set_direction(gtkMenuButton, direction);
388 	}
389 
390 	/**
391 	 * Sets the style of the button.
392 	 *
393 	 * Params:
394 	 *     hasFrame = whether the button should have a visible frame
395 	 */
396 	public void setHasFrame(bool hasFrame)
397 	{
398 		gtk_menu_button_set_has_frame(gtkMenuButton, hasFrame);
399 	}
400 
401 	/**
402 	 * Sets the name of an icon to show inside the menu button.
403 	 *
404 	 * Setting icon name resets [property@Gtk.MenuButton:label] and
405 	 * [property@Gtk.MenuButton:child].
406 	 *
407 	 * If [property@Gtk.MenuButton:always-show-arrow] is set to `TRUE` and
408 	 * [property@Gtk.MenuButton:direction] is not `GTK_ARROW_NONE`, a dropdown arrow
409 	 * will be shown next to the icon.
410 	 *
411 	 * Params:
412 	 *     iconName = the icon name
413 	 */
414 	public void setIconName(string iconName)
415 	{
416 		gtk_menu_button_set_icon_name(gtkMenuButton, Str.toStringz(iconName));
417 	}
418 
419 	/**
420 	 * Sets the label to show inside the menu button.
421 	 *
422 	 * Setting a label resets [property@Gtk.MenuButton:icon-name] and
423 	 * [property@Gtk.MenuButton:child].
424 	 *
425 	 * If [property@Gtk.MenuButton:direction] is not `GTK_ARROW_NONE`, a dropdown
426 	 * arrow will be shown next to the label.
427 	 *
428 	 * Params:
429 	 *     label = the label
430 	 */
431 	public void setLabel(string label)
432 	{
433 		gtk_menu_button_set_label(gtkMenuButton, Str.toStringz(label));
434 	}
435 
436 	/**
437 	 * Sets the `GMenuModel` from which the popup will be constructed.
438 	 *
439 	 * If @menu_model is %NULL, the button is disabled.
440 	 *
441 	 * A [class@Gtk.Popover] will be created from the menu model with
442 	 * [ctor@Gtk.PopoverMenu.new_from_model]. Actions will be connected
443 	 * as documented for this function.
444 	 *
445 	 * If [property@Gtk.MenuButton:popover] is already set, it will be
446 	 * dissociated from the @menu_button, and the property is set to %NULL.
447 	 *
448 	 * Params:
449 	 *     menuModel = a `GMenuModel`, or %NULL to unset and disable the
450 	 *         button
451 	 */
452 	public void setMenuModel(MenuModel menuModel)
453 	{
454 		gtk_menu_button_set_menu_model(gtkMenuButton, (menuModel is null) ? null : menuModel.getMenuModelStruct());
455 	}
456 
457 	/**
458 	 * Sets the `GtkPopover` that will be popped up when the @menu_button is clicked.
459 	 *
460 	 * If @popover is %NULL, the button is disabled.
461 	 *
462 	 * If [property@Gtk.MenuButton:menu-model] is set, the menu model is dissociated
463 	 * from the @menu_button, and the property is set to %NULL.
464 	 *
465 	 * Params:
466 	 *     popover = a `GtkPopover`, or %NULL to unset and disable the button
467 	 */
468 	public void setPopover(Widget popover)
469 	{
470 		gtk_menu_button_set_popover(gtkMenuButton, (popover is null) ? null : popover.getWidgetStruct());
471 	}
472 
473 	/**
474 	 * Sets whether menu button acts as a primary menu.
475 	 *
476 	 * Primary menus can be opened with the <kbd>F10</kbd> key.
477 	 *
478 	 * Params:
479 	 *     primary = whether the menubutton should act as a primary menu
480 	 *
481 	 * Since: 4.4
482 	 */
483 	public void setPrimary(bool primary)
484 	{
485 		gtk_menu_button_set_primary(gtkMenuButton, primary);
486 	}
487 
488 	/**
489 	 * If true, an underline in the text indicates a mnemonic.
490 	 *
491 	 * Params:
492 	 *     useUnderline = %TRUE if underlines in the text indicate mnemonics
493 	 */
494 	public void setUseUnderline(bool useUnderline)
495 	{
496 		gtk_menu_button_set_use_underline(gtkMenuButton, useUnderline);
497 	}
498 
499 	/**
500 	 * Emitted to when the menu button is activated.
501 	 *
502 	 * The `::activate` signal on `GtkMenuButton` is an action signal and
503 	 * emitting it causes the button to pop up its menu.
504 	 *
505 	 * Since: 4.4
506 	 */
507 	gulong addOnActivate(void delegate(MenuButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
508 	{
509 		return Signals.connect(this, "activate", dlg, connectFlags ^ ConnectFlags.SWAPPED);
510 	}
511 }